<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>学生录入</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/qcby/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/qcby/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="/qcby/layuiadmin/style/login.css" media="all">
  <link href="/qcby/favicon.ico" rel="shortcut icon" />
<!--  POI-->
</head>
<body>

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>学生录入</h2>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
          <input type="text" name="user" id="LAY-user-login-user" lay-verify="user" placeholder="学号" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
          <input type="text" name="nickname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="姓名" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
          <input type="text" name="claName" id="LAY-user-login-claName" lay-verify="claName" placeholder="录入班级" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
          <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
        </div>

        <div class="layui-form-item">
          <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">录　入</button>
        </div>

      </div>
      <form action="/qcby/file/upload" method="post" enctype="multipart/form-data" style="width: 400px;">
        批量录入(.xls .xlsx)：<input type="file" name="file" width="120px">
        <input style="position: absolute;width: 50px;height: 30px;margin-top: -4px;margin-left: -70px; " type="submit" value="上传">
      </form>
      <a href="/qcby/file/demo.xlsx" download="demo.xlsx">下载模板</a>
      <input id="rootFile" th:value="${msg}" style="display: none;" />
      <h4 style="color: red" th:text="${info}"></h4>
      <input style="margin-top: 20px;" id="batch" class="layui-btn layui-btn-fluid" value="批量录入">


    </div>

    <div class="layui-trans layadmin-user-login-footer">
      
      <p>© 2020 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
      <p>
        <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
        <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
        <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
      </p>
    </div>

  </div>
  <script src="/qcby/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/qcby/layuiadmin/' //静态资源所在路径
    }).extend({
      index: '/lib/index' //主入口模块
    }).use(['index', 'user','layer'], function(){
      var $ = layui.$
              ,setter = layui.setter
              ,admin = layui.admin
              ,form = layui.form
              ,layer = layui.layer;

      form.render();

      //提交
      form.on('submit(LAY-user-reg-submit)', function(obj){
        var field = obj.field;

        //确认密码
        if(field.password !== field.repass){
          return layer.msg('两次密码输入不一致');
        }

        //是否同意用户协议
        if(!field.agreement){
          return layer.msg('你必须同意用户协议才能注册');
        }

        //请求接口
        admin.req({
          url: '/qcby/login/registerStudent' //实际使用请改成服务端真实接口
          ,data: field
          ,type:'post'
          ,done: function(res){

            if(res.code == 0){
              layer.msg('录入成功', {
                offset: '15px'
                ,icon: 1
                ,time: 1000
              }, function(){

              });
            }else{
              layer.msg(res.data.msg, {
                offset: '30px'
                ,icon: 2
                ,time: 1000
              }, function(){
                location.reload();
              });
            }

          }
        });
        return false;
      });

      $("#batch").bind("click",function () {
          var fileName ="E://testSystem//" + $("#rootFile").val();
          $.ajax({
            type: "post",
            url: "/qcby/teacher/batchInsert",
            data: {
              fileName:fileName
            },
            cache: false,
            async : false,
            //dataType: "JSON",
            success: function (data) {
              if(data.code == 0){
                layer.alert("录入成功",{icon:1});
              }else {
                layer.alert(data.msg,{icon:2})
              }
            }
          });
      })

    });
  </script>
</body>
</html>